package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.entity.Admin;
import com.atguigu.entity.Permission;
import com.atguigu.service.AdminService;
import com.atguigu.service.PermissionService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


/**
 * @author:ahang
 * @create:2022-07-19 18:40
 * @Description:
 */
@Controller
//不写@RequestMapping直接访问index.xml页面
public class IndexController {
    @Reference
    private PermissionService permissionService;
    @Reference
    private AdminService adminService;

    @RequestMapping
    public String index(Model model){

        //查询admin数据,显示admin头像等动态数据
        Long adminId = 1L;  //超级管理员
//        Long adminId = 10L; //普通用户
        Admin admin = adminService.getById(adminId);
        model.addAttribute("admin",admin);
        List<Permission> permissionList = this.permissionService.findMenuPermissionByAdminId(adminId);
        model.addAttribute("permissionList",permissionList);
        return "frame/index";
    }

    @RequestMapping("/main")
    public String main(){

        return "frame/main";
    }

    /**
     * 授权页面
     * @return
     */
    @RequestMapping("/loginPage")
    public String loginPage(){
        return "frame/login";
    }

}
